using System;
using System.Web.UI;

namespace MyControls.DataSources.CompositeHierarchicalDataSource {
    /// <summary>
    /// A collection of datasource controls
    /// </summary>
    public class DataSourceCollection : ControlCollection {
        /// <summary>
        /// Constructs the collection with the specified owner.
        /// </summary>
        /// <param name="owner">The <see cref="System.Web.UI.Control"/> that owns this collection.</param>
        public DataSourceCollection(Control owner)
            : base(owner) {
        }

        public override void Add(Control child) {
            if (!(child is IDataSource))
                throw new ArgumentException("DataSourceCollection items must implement IDataSource.");
            base.Add(child);
        }

        public override void AddAt(int index, Control child) {
            if (!(child is IDataSource))
                throw new ArgumentException("DataSourceCollection items must implement IDataSource.");
            base.AddAt(index, child);
        }
    }
}